package com.example.question.list.list1;

/**
 * @Date 2023-07-06
 * @Author Jonathan
 */
public class Code13_328 {
    public static void main(String[] args) {
        // 1,2,3,4,5,6
        Code13_328 code = new Code13_328();
        ListNode listNode = List.createList(new int[]{1, 2, 3, 4, 5});
        ListNode node = code.oddEvenList(listNode);
        List.printLink(node);

    }

    public ListNode oddEvenList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode slow0 = head;
        ListNode fast0 = head;
        ListNode slow1 = head.next;
        ListNode oddHead = head.next;
        ListNode fast1 = head.next;
        while (fast1 != null && fast1.next != null) {
            fast1 = fast1.next.next;
            fast0 = fast0.next.next;
            slow1.next = fast1;
            slow0.next = fast0;
            slow1 = slow1.next;
            slow0 = slow0.next;
        }
        slow0.next = oddHead;
        return head;
    }
}
